<template>
	<view>
		<view class="detail-list">
			<view v-for="(item,i) in dateilList" :key="i" @click="gotoDetail(item)">
				<detail-bar :item="item"></detail-bar>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 请求列表参数对象
				queryObj: {
					//参数关键词
					query: '',
					//商品分类id
					cid: '',
					//页码
					pagenum: 1,
					//每页条数
					pagesize: 10
				},
				dateilList: [],
				total: 0,
				//节流阀
				isloading: false

			};
		},
		onLoad(options) {
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''

			this.getDetailList()
		},

		methods: {
			//获取详细信息
			async getDetailList(cb) {
				this.isloading = true
				// const {
					// data: res
				// } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
				this.isloading = false
				
				cb && cb()
				// if (res.meta.status !== 200) return uni.$showMsg()

				this.dateilList = [...this.dateilList, ...res.message.goods]
				this.total = res.message.total
			},
			//列表详情
			gotoDetail(item){
				uni.navigateTo({
					url:'/subpkg/list-detail/list-detail?goods_id='+item.goods_id
				})
			}
			
		},
		// 上拉加载更多
		onReachBottom() {
			if (this.queryObj.pagenum * this.queryObj.pagesize >= this.total) return uni.$showMsg('我就已经到底咯')
			
			if(this.isloading) return
			this.queryObj.pagenum++
			this.getDetailList()
		},
		// 下拉刷新
		onPullDownRefresh(){
			//重置数据
			this.queryObj.pagenum=1
			this.total=0
			this.isloading=false
			this.dateilList=[]
			//重新发起请求
			this.getDetailList(()=>uni.stopPullDownRefresh())
		}
	}
</script>

<style lang="scss">

</style>